<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="小有的个人主页">
    <meta name="description" content="小有的个人页面，喜欢收集一些感兴趣的东西，爱好设计和编程、旅行、摄影。在这里你可以观看到我近期的作品...">
    <meta name="author" content="小有的个人主页">
    <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-redefine.png">
    
    <!--- Seo Part-->
    
    <link rel="canonical" href="https://weiyouyuan168.gitee.io/new-blog/2023/03/10/java/"/>
    <meta name="robots" content="index,follow">
    <meta name="googlebot" content="index,follow">
    <meta name="revisit-after" content="1 days">
    <meta property="og:type" content="article">
    <meta property="og:title" content="Java复习题">
    <meta property="og:description" content="小有的个人页面，喜欢收集一些感兴趣的东西，爱好设计和编程、旅行、摄影。在这里你可以观看到我近期的作品...">
    <meta property="og:url" content="https://weiyouyuan168.gitee.io/new-blog2023/03/10/Java/">
    
    <meta property="og:site_name" content="小有·Xiao You Zi的个人主页">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="twitter:title" content="Java复习题">
    <meta name="twitter:description" content="小有的个人页面，喜欢收集一些感兴趣的东西，爱好设计和编程、旅行、摄影。在这里你可以观看到我近期的作品...">
    <meta name="twitter:image" content="/new-blog/images/redefine-logo.svg">
    <!--- Icon Part-->
    <link rel="icon" type="image/png" href="./new-blog/images/redefine-logo.svg" sizes="192x192">
    <link rel="apple-touch-icon" sizes="180x180" href="./new-blog/images/redefine-logo.svg">
    <meta name="theme-color" content="#005080">
    <link rel="shortcut icon" href="././new-blog/images/redefine-logo.svg">
    
    <title>
        
            Java复习题 -
        
        小有·Xiao You Zi的个人主页
    </title>
    
<link rel="stylesheet" href="./css/style.css">

    
<link rel="stylesheet" href="./assets/fonts.css">

    
    
        <link href="" rel="stylesheet">
    
    
    <script id="hexo-configurations">
    let REDEFINE = window.REDEFINE || {};
    REDEFINE.hexo_config = {"hostname":"weiyouyuan168.gitee.io","root":"./","language":"zh-CN"};
    REDEFINE.theme_config = {"toc":{"enable":true,"number":false,"expand_all":true,"init_open":true},"style":{"primary_color":"#005080","avatar":"/new-blog/images/redefine-avatar.svg","favicon":"/new-blog/images/redefine-logo.svg","og_image":{"enable":false,"image_url":null},"article_img_align":"center","right_side_width":"210px","content_max_width":"1000px","nav_color":{"left":"#f78736","right":"#367df7","transparency":35},"hover":{"shadow":true,"scale":false},"first_screen":{"enable":true,"background_image":{"light":"/new-blog/images/wallhaven-wqery6-light.webp","dark":"/new-blog/images/wallhaven-wqery6-dark.webp"},"title_color":{"light":"#fff","dark":"#d1d1b6"},"description":"小有的个人主页","custom_font":{"enable":false,"font_family":null,"font_url":null}},"scroll":{"progress_bar":{"enable":true},"percent":{"enable":false}}},"local_search":{"enable":false,"preload":true},"code_block":{"copy":true,"style":"mac","custom_font":{"enable":true,"font_family":null,"font_url":null}},"pjax":{"enable":true},"lazyload":{"enable":true},"version":"1.2.0","friend_links":{"columns":2},"home_article":{"date_format":"auto","category":{"enable":true,"limit":3},"tag":{"enable":true,"limit":3}},"plugins":{"aplayer":{"enable":false,"audio":[{"name":null,"artist":null,"url":null,"cover":null},{"name":null,"artist":null,"url":null,"cover":null}]}}};
    REDEFINE.language_ago = {"second":"%s 秒前","minute":"%s 分钟前","hour":"%s 小时前","day":"%s 天前","week":"%s 周前","month":"%s 个月前","year":"%s 年前"};
  </script>
    
    
<link rel="stylesheet" href="./fontawesome/fontawesome.min.css">

    
<link rel="stylesheet" href="./fontawesome/brands.min.css">

    
<link rel="stylesheet" href="./fontawesome/solid.min.css">

    
<link rel="stylesheet" href="./fontawesome/regular.min.css">

    
    
    
    
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
<div class="progress-bar-container">
    
        <span class="scroll-progress-bar"></span>
    

    
        <span class="pjax-progress-bar"></span>
        <span class="pjax-progress-icon">
            <i class="fa-solid fa-circle-notch fa-spin"></i>
        </span>
    
</div>


<main class="page-container">

    

    <div class="page-main-content">

        <div class="page-main-content-top">
            <header class="menu-wrapper">
    
    <div class="menu-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                
                小有·Xiao You Zi的个人主页
                
            </a>
        </div>

        <div class="right">
            <!-- PC -->
            <div class="pc">
                <ul class="menu-list">
                    
                        
                            <li class="menu-item">
                                <!-- Menu -->
                                <a class="" 
                                    href="./%E9%A6%96%E9%A1%B5"  >
                                    
                                        
                                            <i class="fa-regular fa-house"></i>
                                        
                                        首页
                                    
                                </a>
                                <!-- Submenu -->
                                
                            </li>
                    
                    
                </ul>
            </div>
            <!-- Mobile -->
            <div class="mobile">
                
                <div class="icon-item menu-bar">
                    <div class="menu-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Mobile drawer -->
    <div class="menu-drawer">
        <ul class="drawer-menu-list">
            
                
                    <li class="drawer-menu-item flex-center">
                        <a class="" 
                        href="./%E9%A6%96%E9%A1%B5"  >
                             
                                
                                    <i class="fa-regular fa-house"></i>
                                
                                首页
                            
                        </a>
                    </li>
                    <!-- Submenu -->
                    
            

        </ul>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="page-main-content-middle">

            <div class="main-content">

                
                    <div class="fade-in-down-animation">
    <div class="post-page-container">
        <div class="article-content-container">

            
            
                <div class="article-title">
                    <h1 class="article-title-regular">Java复习题</h1>
                </div>
            
                
            

            
                <div class="article-header">
                    <div class="avatar">
                        <img src="././new-blog/images/redefine-avatar.svg">
                    </div>
                    <div class="info">
                        <div class="author">
                            <span class="name">小有的个人主页</span>
                            
                                <span class="author-label">lol</span>
                            
                        </div>
                        <div class="meta-info">
                            <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fa-regular fa-pen-fancy"></i>&nbsp;
        <span class="pc">2023-03-10 23:12:50</span>
        <span class="mobile">2023-03-10 23:12</span>
        <span class="hover-info">创建</span>
    </span>
    
        <span class="article-date article-meta-item">
            <i class="fa-regular fa-wrench"></i>&nbsp;
            <span class="pc">2023-03-12 15:48:59</span>
            <span class="mobile">2023-03-12 15:48</span>
            <span class="hover-info">更新</span>
        </span>
    

    
    

    
    
    
    
        <span class="article-pv article-meta-item">
            <i class="fa-regular fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                        </div>
                    </div>
                </div>
            

            <div class="article-content markdown-body">
                <p>Java代码复习题</p>
<span id="more"></span>

<h3 id="请根据请根据自己理解能力进行适合自己的方法选择"><a href="#请根据请根据自己理解能力进行适合自己的方法选择" class="headerlink" title="请根据请根据自己理解能力进行适合自己的方法选择"></a>请根据请根据自己理解能力进行适合自己的方法选择</h3><h5 id="接口实现，创建一个接口，接口中有两方法，一个是求面积的，一个是求周长的。创建两个实现类实现"><a href="#接口实现，创建一个接口，接口中有两方法，一个是求面积的，一个是求周长的。创建两个实现类实现" class="headerlink" title="接口实现，创建一个接口，接口中有两方法，一个是求面积的，一个是求周长的。创建两个实现类实现"></a>接口实现，创建一个接口，接口中有两方法，一个是求面积的，一个是求周长的。创建两个实现类实现</h5><p><img lazyload src="/images/loading.svg" data-src="https://fork-basement-a2a.notion.site/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F7e01e6a8-683c-49b9-8843-69e0b55a84c6%2FUntitled.png?id=64a4626f-5e3f-44e6-aab1-d8dcf9531107&table=block&spaceId=6962eddb-775d-4c73-a702-d2ce821fec72&width=1320&userId=&cache=v2"></p>
<h6 id="实现代码"><a href="#实现代码" class="headerlink" title="实现代码"></a>实现代码</h6><h6 id="第一种方法"><a href="#第一种方法" class="headerlink" title="第一种方法"></a>第一种方法</h6><div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br></pre></td><td class="code"><pre><code class="hljs Java"> <span class="hljs-keyword">public</span> class 面积 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Rect</span>().areaLength(<span class="hljs-number">1.4</span>,<span class="hljs-number">1.2</span>);<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Circle</span>().areaLength(<span class="hljs-number">1.8</span>);<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Shapes</span>().areaLength(<span class="hljs-number">1.8</span>, <span class="hljs-number">2.4</span>, <span class="hljs-number">2.4</span>);<br>    &#125;<br>&#125;<br><br><span class="hljs-comment">// 定义三个可传递多个参数方法，</span><br><span class="hljs-keyword">interface</span> <span class="hljs-title class_">shape</span> &#123;<br>    <span class="hljs-comment">//    面积</span><br>    <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a)</span>;<br><br>    <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b)</span>;<br><br>    <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b, <span class="hljs-type">double</span> c)</span>;<br><br>&#125;<br><br><span class="hljs-comment">//矩形</span><br><span class="hljs-comment">//通过继承shape方法</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Rect</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">shape</span> &#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a)</span> &#123;<br><br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b)</span> &#123;<br>        System.out.println(<span class="hljs-string">&quot;矩形的面积为：&quot;</span>+a * b);<br>        System.out.println(<span class="hljs-string">&quot;矩形的周长为：&quot;</span>+(a  + b) *<span class="hljs-number">2</span>);<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b, <span class="hljs-type">double</span> c)</span> &#123;<br><br>    &#125;<br><br>&#125;<br><br><span class="hljs-comment">//圆形的面积、周长</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Circle</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">shape</span>&#123;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a)</span> &#123;<br>        System.out.println(<span class="hljs-string">&quot;圆形的面积为：&quot;</span>+ <span class="hljs-number">3.14</span>*a*a);<br>        System.out.println(<span class="hljs-string">&quot;圆形的周长为：&quot;</span>+<span class="hljs-number">3.14</span> * a *<span class="hljs-number">2</span>);<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b)</span> &#123;<br><br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b, <span class="hljs-type">double</span> c)</span> &#123;<br><br>    &#125;<br>&#125;<br><br><span class="hljs-comment">//三角形 面积、周长</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Shapes</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">shape</span>&#123;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a)</span> &#123;<br><br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b)</span> &#123;<br><br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span> a, <span class="hljs-type">double</span> b, <span class="hljs-type">double</span> c)</span> &#123;<br>        <span class="hljs-type">double</span> p=(a+b+c)/<span class="hljs-number">2</span>;<br>        System.out.println(<span class="hljs-string">&quot;三角形的面积为：&quot;</span>+ Math.sqrt(p*(p-a)*(p-b)*(p-c)));<br>        System.out.println(<span class="hljs-string">&quot;三角形的周长为：&quot;</span>+ (a+b+c));<br>    &#125;<br>&#125;<br><br><br></code></pre></td></tr></table></figure></div>

<h6 id="第二种方法"><a href="#第二种方法" class="headerlink" title="第二种方法"></a>第二种方法</h6><div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs Java"><span class="hljs-keyword">public</span> class 面积 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>     <span class="hljs-keyword">new</span> <span class="hljs-title class_">Rect1</span>().areaLength(<span class="hljs-number">1.2</span>, <span class="hljs-number">2.4</span>);<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Circle1</span>().areaLength(<span class="hljs-number">1.4</span>);<br>        <span class="hljs-keyword">new</span> <span class="hljs-title class_">Shapes1</span>().areaLength(<span class="hljs-number">1.4</span>,<span class="hljs-number">2.8</span>,<span class="hljs-number">2.8</span>);<br>    &#125;<br>    <span class="hljs-keyword">class</span> <span class="hljs-title class_">Shapes1</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">she</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span>... a)</span> &#123;<br>        <span class="hljs-type">double</span> p=(a[<span class="hljs-number">0</span>]+a[<span class="hljs-number">1</span>]+a[<span class="hljs-number">2</span>])/<span class="hljs-number">2</span>;<br>        System.out.println(<span class="hljs-string">&quot;三角形面积：&quot;</span>+Math.sqrt(p*(p-a[<span class="hljs-number">0</span>])*(p-a[<span class="hljs-number">1</span>])*(p-a[<span class="hljs-number">2</span>])));<br>        System.out.println(<span class="hljs-string">&quot;三角形周长：&quot;</span>+ <span class="hljs-number">2</span>*p);<br>    &#125;<br>&#125;<br><br><span class="hljs-comment">//矩形</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Rect1</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">she</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span>... a)</span> &#123;<br>        System.out.println(<span class="hljs-string">&quot;矩形面积：&quot;</span>+ a[<span class="hljs-number">0</span>]*a[<span class="hljs-number">1</span>]);<br>        System.out.println(<span class="hljs-string">&quot;矩形周长：&quot;</span>+ (a[<span class="hljs-number">0</span>] * a[<span class="hljs-number">1</span>])*<span class="hljs-number">2</span>);<br>    &#125;<br>&#125;<br><br><span class="hljs-comment">//圆形</span><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">Circle1</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">she</span>&#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span>... a)</span> &#123;<br>        System.out.println(<span class="hljs-string">&quot;圆形面积：&quot;</span>+ <span class="hljs-number">3.14</span>* a[<span class="hljs-number">0</span>] * a[<span class="hljs-number">0</span>]);<br>        System.out.println(<span class="hljs-string">&quot;圆形周长：&quot;</span>+ (<span class="hljs-number">3.14</span>* a[<span class="hljs-number">0</span>] * <span class="hljs-number">2</span>));<br>    &#125;<br>&#125;<br><br><span class="hljs-keyword">interface</span> <span class="hljs-title class_">she</span>&#123;<br>    <span class="hljs-keyword">void</span> <span class="hljs-title function_">areaLength</span><span class="hljs-params">(<span class="hljs-type">double</span>... a)</span>;<br>&#125;<br>&#125;<br></code></pre></td></tr></table></figure></div>

<h5 id="给定一个字符串，计算字符串中关键词出现的次数"><a href="#给定一个字符串，计算字符串中关键词出现的次数" class="headerlink" title="给定一个字符串，计算字符串中关键词出现的次数"></a>给定一个字符串，计算字符串中关键词出现的次数</h5><h6 id="第一种方法-1"><a href="#第一种方法-1" class="headerlink" title="第一种方法"></a>第一种方法</h6><div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs Java"><span class="hljs-keyword">public</span> class 朋友类 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        <span class="hljs-type">String</span> <span class="hljs-variable">song</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;这些年一个人，风也过，雨也走，有过泪，有过错 , \n&quot;</span> +<br>                <span class="hljs-string">&quot;还记得坚持甚么，真爱过才会懂，会寂寞会回首，终有梦终有你在心中。\n&quot;</span> +<br>                <span class="hljs-string">&quot;朋友一生一起走，那些日子不再有，一句话，一辈子，一生情，一杯酒。\n&quot;</span> +<br>                <span class="hljs-string">&quot;朋友不曾孤单过，一声朋友你会懂，还有伤，还有痛，还要走，还有我。&quot;</span>;<br><br>        countString(song);<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">countString</span><span class="hljs-params">(String str)</span> &#123;<br>        <span class="hljs-type">int</span> <span class="hljs-variable">count</span> <span class="hljs-operator">=</span> str.split(<span class="hljs-string">&quot;朋友&quot;</span>).length - <span class="hljs-number">1</span>;<br>        System.out.println(<span class="hljs-string">&quot;朋友出现的次数：&quot;</span> + count);<br>    &#125;<br>&#125;<br><br><br></code></pre></td></tr></table></figure></div>

<h6 id="第二种方法-1"><a href="#第二种方法-1" class="headerlink" title="第二种方法"></a>第二种方法</h6><div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs Java"><span class="hljs-keyword">public</span> class 朋友类 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        <span class="hljs-type">String</span> <span class="hljs-variable">zi</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;这些年一个人，风也过，雨也走，有过泪，有过错，还记得坚持甚么，真爱过才会懂，会寂寞会回首，终有梦终有你在心中。朋友一生一起走，那些日子不再有，一句话，一辈子，一生情，一杯酒。朋友不曾孤单过，一声朋友你会懂，还有伤，还有痛，还要走，还有我。&quot;</span>;<br>        <span class="hljs-type">String</span> <span class="hljs-variable">search</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;朋友&quot;</span>;<br><span class="hljs-comment">//       第一种使用 indexOf与substring进行</span><br>        <span class="hljs-type">int</span> <span class="hljs-variable">conum</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>        <span class="hljs-type">int</span> i;<br>        <span class="hljs-keyword">while</span> (zi.contains(search)) &#123;<br>            i = zi.indexOf(search);<br>            zi = zi.substring(i + search.length());<br>            conum++;<br>        &#125;<br>        System.out.println(conum);<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure></div>

<h5 id="给定一个集合，用迭代器获取值并打印"><a href="#给定一个集合，用迭代器获取值并打印" class="headerlink" title="给定一个集合，用迭代器获取值并打印"></a>给定一个集合，用迭代器获取值并打印</h5><p><font color="#EB1C27">注意 （List.of） 这个方法只在 JDK 11 以上使用 1.8 请使用 （Arrays.asList）</font></p>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><code class="hljs Java"><span class="hljs-keyword">public</span> class 迭代器 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        listString();<br>        ListNum();<br>    &#125;<br><br>    <span class="hljs-comment">//list 集合的</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">listString</span><span class="hljs-params">()</span>&#123;<br>        String[] arrStr = &#123;<span class="hljs-string">&quot;one&quot;</span>,<span class="hljs-string">&quot;two&quot;</span>,<span class="hljs-string">&quot;three&quot;</span>,<span class="hljs-string">&quot;four&quot;</span>,<span class="hljs-string">&quot;five&quot;</span>,<span class="hljs-string">&quot;six&quot;</span>,<span class="hljs-string">&quot;seven&quot;</span>,<span class="hljs-string">&quot;eight&quot;</span>&#125;;<br>        List&lt;String&gt; list = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;&gt;();<br>        list.addAll(List.of(arrStr));<br>        <span class="hljs-type">Iterator</span> <span class="hljs-variable">it</span> <span class="hljs-operator">=</span> list.iterator();<br>        <span class="hljs-keyword">while</span> (it.hasNext())&#123;<br>            <span class="hljs-type">String</span> <span class="hljs-variable">str</span> <span class="hljs-operator">=</span> (String) it.next();<br>            System.out.println(str);<br>        &#125;<br>    &#125;<br>    <span class="hljs-comment">// set集合的</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">ListNum</span><span class="hljs-params">()</span>&#123;<br>        <span class="hljs-type">Set</span> <span class="hljs-variable">set</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">TreeSet</span>();<br>        set.add(<span class="hljs-number">2</span>);<br>        set.add(<span class="hljs-number">5</span>);<br>        set.add(<span class="hljs-number">8</span>);<br>        <span class="hljs-type">Iterator</span> <span class="hljs-variable">it</span> <span class="hljs-operator">=</span> set.iterator();<br>        <span class="hljs-keyword">while</span> (it.hasNext())&#123;<br>            System.out.println(it.next());<br>        &#125;<br><br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></div>
<h5 id="字节流复制-文件复制"><a href="#字节流复制-文件复制" class="headerlink" title="字节流复制,文件复制"></a>字节流复制,文件复制</h5><h6 id="第一种方法-2"><a href="#第一种方法-2" class="headerlink" title="第一种方法"></a>第一种方法</h6><div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs Java"><span class="hljs-keyword">public</span> class 文件复制 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        <span class="hljs-type">FileInputStream</span> <span class="hljs-variable">fis</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">FileInputStream</span>(<span class="hljs-string">&quot;G:\\java的File类\\1.png&quot;</span>);<br>        <span class="hljs-type">FileOutputStream</span> <span class="hljs-variable">fos</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">FileOutputStream</span>(<span class="hljs-string">&quot;G:\\java的File类\\2.png&quot;</span>);<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-type">int</span> i;<br>            <span class="hljs-type">byte</span>[] buff = <span class="hljs-keyword">new</span> <span class="hljs-title class_">byte</span>[<span class="hljs-number">1024</span>]; <span class="hljs-comment">//利用效仿缓冲流</span><br>            <span class="hljs-keyword">while</span> ((i = fis.read(buff)) != -<span class="hljs-number">1</span>) &#123;<br>                fos.write(buff, <span class="hljs-number">0</span>, i);<br>            &#125;<br>        &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>            e.printStackTrace();<br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">if</span> (fis != <span class="hljs-literal">null</span>) &#123;<br>                fis.close();<br>            &#125;<br>            <span class="hljs-keyword">if</span> (fos != <span class="hljs-literal">null</span>) &#123;<br>                fos.close();<br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></div>
<h6 id="第二种方法-2"><a href="#第二种方法-2" class="headerlink" title="第二种方法"></a>第二种方法</h6><ol>
<li>注意这里的第一种buff是模拟每隔1024截取一次进行存储 </li>
<li>第二种这里的方法也是一样原理方法是被java优化过因此这个名称开头都会有buff<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs Java">       <span class="hljs-keyword">public</span> class 拷贝流 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        BufferedInputStream sr= <span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedInputStream</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">FileInputStream</span>(<span class="hljs-string">&quot;G:\\java的File类\\1.png&quot;</span>));<br>        BufferedOutputStream sc=<span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedOutputStream</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">FileOutputStream</span>(<span class="hljs-string">&quot;G:\\java的File类\\2.png&quot;</span>));<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-type">int</span> i;<br>            <span class="hljs-keyword">while</span> ((i=(sr.read()))!=-<span class="hljs-number">1</span>)&#123;<br>                sc.write(i);<br>            &#125;<br>        &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">RuntimeException</span>(e);<br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">if</span> (sr!=<span class="hljs-literal">null</span>)&#123;<br>                sr.close();<br>            &#125;<br>            <span class="hljs-keyword">if</span> (sc!=<span class="hljs-literal">null</span>)&#123;<br>                sc.close();<br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></div></li>
</ol>
<h4 id="递归遍历目录文件，找出目录内带有txt为后缀的文件"><a href="#递归遍历目录文件，找出目录内带有txt为后缀的文件" class="headerlink" title="递归遍历目录文件，找出目录内带有txt为后缀的文件"></a>递归遍历目录文件，找出目录内带有txt为后缀的文件</h4><p><strong>第一种</strong></p>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs Java"> <span class="hljs-keyword">public</span> class 查询文件下的txt后缀文件 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        metoh(<span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(<span class="hljs-string">&quot;D:\\Desktop\\物联网第一学期\\java作业\\案例&quot;</span>));<br>    &#125;<br>   <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">metoh</span><span class="hljs-params">(File f1)</span>&#123;<br>        f1.list(<span class="hljs-keyword">new</span> <span class="hljs-title class_">FilenameFilter</span>()&#123;<br>            <span class="hljs-meta">@Override</span><br>            <span class="hljs-keyword">public</span> <span class="hljs-type">boolean</span> <span class="hljs-title function_">accept</span><span class="hljs-params">(File dir, String name)</span> &#123;<br>                <span class="hljs-type">File</span> <span class="hljs-variable">file</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(dir, name);<br>                <span class="hljs-keyword">if</span> (file.getName().endsWith(<span class="hljs-string">&quot;txt&quot;</span>))&#123;<br>                    System.out.println(file);<br>                    <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>                &#125;<br>                <span class="hljs-keyword">if</span> (file.isDirectory() &amp;&amp; file.getName()!=<span class="hljs-literal">null</span>)&#123;<br>                    metoh(file);<br>                &#125;<br>                <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;<br>            &#125;<br>        &#125;);<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></div>

<p><strong>第二种</strong></p>
<div class="highlight-container" data-rel="Java"><figure class="iseeu highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><code class="hljs Java"> <span class="hljs-keyword">public</span> class 查询文件下的txt后缀文件 &#123;<br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>        <span class="hljs-type">File</span> <span class="hljs-variable">f</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(<span class="hljs-string">&quot;E:/file&quot;</span>);<br>        fileDir(f);<br>    &#125;<br><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">fileDir</span><span class="hljs-params">(File dir)</span> &#123;<br>        File[] files = dir.listFiles();<br>        <span class="hljs-keyword">for</span> (File file : files) &#123;<br>            <span class="hljs-keyword">if</span> (file.isFile()) &#123;<br>                <span class="hljs-type">boolean</span> <span class="hljs-variable">flag</span> <span class="hljs-operator">=</span> file.getName().endsWith(<span class="hljs-string">&quot;txt&quot;</span>);<br>                <span class="hljs-keyword">if</span> (flag) &#123;<br>                    System.out.println(<span class="hljs-string">&quot;文件名：&quot;</span> + file.getName());<br>                &#125;<br>            &#125;<br>            <span class="hljs-keyword">if</span> (file.isDirectory() &amp;&amp; file.listFiles() != <span class="hljs-literal">null</span>) &#123;<br>                fileDir(file);<br>            &#125;<br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure></div>
            </div>

            
                <div class="post-copyright-info">
                    <div class="article-copyright-info-container">
    <ul>
        <li>本文标题：Java复习题</li>
        <li>本文作者：小有的个人主页</li>
        <li>创建时间：2023-03-10 23:12:50</li>
        <li>
            本文链接：https://redefine.ohevan.com/2023/03/10/Java/
        </li>
        <li>
            版权声明：本博客所有文章除特别声明外，均采用 <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">BY-NC-SA</a> 许可协议。转载请注明出处！
        </li>
    </ul>
</div>

                </div>
            

            

            

            
                <div class="article-nav">
                    
                        <div class="article-prev">
                            <a class="prev"
                            rel="prev"
                            href="./2023/03/12/%E5%A1%AB%E7%A9%BA%E9%A2%98/"
                            >
                                <span class="left arrow-icon flex-center">
                                    <i class="fa-solid fa-chevron-left"></i>
                                </span>
                                <span class="title flex-center">
                                    <span class="post-nav-title-item">填空题</span>
                                    <span class="post-nav-item">上一篇</span>
                                </span>
                            </a>
                        </div>
                    
                    
                        <div class="article-next">
                            <a class="next"
                            rel="next"
                            href="./2022/01/16/axiso%E9%85%8D%E7%BD%AE/"
                            >
                                <span class="title flex-center">
                                    <span class="post-nav-title-item">axiso配置</span>
                                    <span class="post-nav-item">下一篇</span>
                                </span>
                                <span class="right arrow-icon flex-center">
                                    <i class="fa-solid fa-chevron-right"></i>
                                </span>
                            </a>
                        </div>
                    
                </div>
            


            
        </div>

        
            <div class="toc-content-container">
                <div class="post-toc-wrap">
    <div class="post-toc">
        <div class="toc-title">此页目录</div>
        <div class="page-title">Java复习题</div>
        <ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AF%B7%E6%A0%B9%E6%8D%AE%E8%AF%B7%E6%A0%B9%E6%8D%AE%E8%87%AA%E5%B7%B1%E7%90%86%E8%A7%A3%E8%83%BD%E5%8A%9B%E8%BF%9B%E8%A1%8C%E9%80%82%E5%90%88%E8%87%AA%E5%B7%B1%E7%9A%84%E6%96%B9%E6%B3%95%E9%80%89%E6%8B%A9"><span class="nav-text">请根据请根据自己理解能力进行适合自己的方法选择</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%8E%A5%E5%8F%A3%E5%AE%9E%E7%8E%B0%EF%BC%8C%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%8E%A5%E5%8F%A3%EF%BC%8C%E6%8E%A5%E5%8F%A3%E4%B8%AD%E6%9C%89%E4%B8%A4%E6%96%B9%E6%B3%95%EF%BC%8C%E4%B8%80%E4%B8%AA%E6%98%AF%E6%B1%82%E9%9D%A2%E7%A7%AF%E7%9A%84%EF%BC%8C%E4%B8%80%E4%B8%AA%E6%98%AF%E6%B1%82%E5%91%A8%E9%95%BF%E7%9A%84%E3%80%82%E5%88%9B%E5%BB%BA%E4%B8%A4%E4%B8%AA%E5%AE%9E%E7%8E%B0%E7%B1%BB%E5%AE%9E%E7%8E%B0"><span class="nav-text">接口实现，创建一个接口，接口中有两方法，一个是求面积的，一个是求周长的。创建两个实现类实现</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E5%AE%9E%E7%8E%B0%E4%BB%A3%E7%A0%81"><span class="nav-text">实现代码</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%AC%AC%E4%B8%80%E7%A7%8D%E6%96%B9%E6%B3%95"><span class="nav-text">第一种方法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%AC%AC%E4%BA%8C%E7%A7%8D%E6%96%B9%E6%B3%95"><span class="nav-text">第二种方法</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%BB%99%E5%AE%9A%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6%E4%B8%B2%EF%BC%8C%E8%AE%A1%E7%AE%97%E5%AD%97%E7%AC%A6%E4%B8%B2%E4%B8%AD%E5%85%B3%E9%94%AE%E8%AF%8D%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0"><span class="nav-text">给定一个字符串，计算字符串中关键词出现的次数</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%AC%AC%E4%B8%80%E7%A7%8D%E6%96%B9%E6%B3%95-1"><span class="nav-text">第一种方法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%AC%AC%E4%BA%8C%E7%A7%8D%E6%96%B9%E6%B3%95-1"><span class="nav-text">第二种方法</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E7%BB%99%E5%AE%9A%E4%B8%80%E4%B8%AA%E9%9B%86%E5%90%88%EF%BC%8C%E7%94%A8%E8%BF%AD%E4%BB%A3%E5%99%A8%E8%8E%B7%E5%8F%96%E5%80%BC%E5%B9%B6%E6%89%93%E5%8D%B0"><span class="nav-text">给定一个集合，用迭代器获取值并打印</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AD%97%E8%8A%82%E6%B5%81%E5%A4%8D%E5%88%B6-%E6%96%87%E4%BB%B6%E5%A4%8D%E5%88%B6"><span class="nav-text">字节流复制,文件复制</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%AC%AC%E4%B8%80%E7%A7%8D%E6%96%B9%E6%B3%95-2"><span class="nav-text">第一种方法</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#%E7%AC%AC%E4%BA%8C%E7%A7%8D%E6%96%B9%E6%B3%95-2"><span class="nav-text">第二种方法</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%80%92%E5%BD%92%E9%81%8D%E5%8E%86%E7%9B%AE%E5%BD%95%E6%96%87%E4%BB%B6%EF%BC%8C%E6%89%BE%E5%87%BA%E7%9B%AE%E5%BD%95%E5%86%85%E5%B8%A6%E6%9C%89txt%E4%B8%BA%E5%90%8E%E7%BC%80%E7%9A%84%E6%96%87%E4%BB%B6"><span class="nav-text">递归遍历目录文件，找出目录内带有txt为后缀的文件</span></a></li></ol></li></ol>

    </div>
</div>
            </div>
        
    </div>
</div>


                

            </div>



        </div>

        <div class="page-main-content-bottom">
            <footer class="footer">
    <div class="info-container">
        <div class="copyright-info">
            &copy;
            
              <span>2022</span>
              -
            
            2023&nbsp;&nbsp;<i class="fa-regular fa-computer-classic"></i>&nbsp;&nbsp;<a href="/">小有的个人主页</a>
        </div>
        
            <script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
            <div class="website-count info-item">
                
                    <span id="busuanzi_container_site_uv" class="busuanzi_container_site_uv">
                        访问人数&nbsp;<span id="busuanzi_value_site_uv" class="busuanzi_value_site_uv"></span>
                    </span>
                
                
                    <span id="busuanzi_container_site_pv" class="busuanzi_container_site_pv">
                        总访问量&nbsp;<span id="busuanzi_value_site_pv" class="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        <div class="theme-info info-item">
           
        </div>
        
        
        
            <div id="start_time_div" style="display:none">
                2022/8/17 11:45:14
            </div>
            <div>
                博客已运行 <span class="odometer" id="runtime_days" ></span> 天 <span class="odometer" id="runtime_hours"></span> 小时 <span class="odometer" id="runtime_minutes"></span> 分钟 <span class="odometer" id="runtime_seconds"></span> 秒
            </div>
        
        
        
            <script async data-pjax>
                try {
                    function odometer_init() {
                    const elements = document.querySelectorAll('.odometer');
                    elements.forEach(el => {
                        new Odometer({
                            el,
                            format: '( ddd).dd',
                            duration: 200
                        });
                    });
                    }
                    odometer_init();
                } catch (error) {}
            </script>
        
        
        
    </div>  
</footer>
        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="tools-list">
        <!-- TOC aside toggle -->
        
            <li class="right-bottom-tools page-aside-toggle">
                <i class="fa-regular fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
    </ul>
</div>

        </div>
    

    <div class="right-bottom-side-tools">
        <div class="side-tools-container">
    <ul class="unfolded-tools-list">
        <li class="right-bottom-tools tool-font-adjust-plus flex-center">
            <i class="fa-regular fa-magnifying-glass-plus"></i>
        </li>

        <li class="right-bottom-tools tool-font-adjust-minus flex-center">
            <i class="fa-regular fa-magnifying-glass-minus"></i>
        </li>

        <li class="right-bottom-tools tool-expand-width flex-center">
            <i class="fa-regular fa-expand"></i>
        </li>

        <li class="right-bottom-tools tool-dark-light-toggle flex-center">
            <i class="fa-regular fa-moon"></i>
        </li>

        <!-- rss -->
        

        
            <li class="right-bottom-tools tool-scroll-to-top flex-center">
                <i class="fa-regular fa-arrow-up"></i>
            </li>
        

        <li class="right-bottom-tools tool-scroll-to-bottom flex-center">
            <i class="fa-regular fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="folded-tools-list">
        <li class="right-bottom-tools tool-toggle-show flex-center">
            <i class="fa-regular fa-cog fa-spin"></i>
        </li>
        
    </ul>
</div>

    </div>

    <div class="image-viewer-container">
    <img src="">
</div>


    


</main>




<script src="./js/utils.js"></script>

<script src="./js/main.js"></script>

<script src="./js/layouts/menu-shrink.js"></script>

<script src="./js/tools/go-top-bottom.js"></script>

<script src="./js/tools/dark-light-toggle.js"></script>





    
<script src="./js/tools/code-block.js"></script>




    
<script src="./js/layouts/lazyload.js"></script>




    
<script src="./js/tools/runtime.js"></script>

    
<script src="./js/layouts/odometer.min.js"></script>

    
<link rel="stylesheet" href="./assets/odometer-theme-minimal.css">





<div class="post-scripts pjax">
    
        
<script src="./js/tools/toc-toggle.js"></script>

<script src="./js/libs/anime.min.js"></script>

<script src="./js/layouts/toc.js"></script>

<script src="./js/plugins/tabs.js"></script>

    
    
</div>


    
<script src="./js/libs/pjax.min.js"></script>

<script>
    window.addEventListener('DOMContentLoaded', () => {
        window.pjax = new Pjax({
            selectors: [
                'head title',
                '.page-container',
                '.pjax'
            ],
            history: true,
            debug: false,
            cacheBust: false,
            timeout: 0,
            analytics: false,
            currentUrlFullReload: false,
            scrollRestoration: false,
            // scrollTo: true,
        });

        document.addEventListener('pjax:send', () => {
            REDEFINE.utils.pjaxProgressBarStart();
        });

        document.addEventListener('pjax:complete', () => {
            REDEFINE.utils.pjaxProgressBarEnd();
            window.pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
            REDEFINE.refresh();
        });
    });
</script>




</body>
</html>
